package com.ddl.controller.core;

import com.ddl.common.exception.ResultModel;
import com.ddl.service.IUserFieldService;
import com.ddl.service.IUserFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2018/11/17
 */
@RestController
@RequestMapping(value = "/app/friend")
public class UserFriendController {
     @Autowired
     IUserFriendService iUserFriendService;
    /**
     * 添加好友
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/addFriend")
    public ResultModel addFriend(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        String friendNo=map.get("friendNo").toString();
        return iUserFriendService.addFriend(userId,friendNo);
    }
    /**
     * 同意好友添加
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/agreeFriend")
    public ResultModel agreeFriend(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        String applyUserId=map.get("applyUserId").toString();
        String status=map.get("status").toString();
        return iUserFriendService.agreeFriend(userId,applyUserId,status);
    }
    /**
     * 我的好友列表
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/friendList")
    public ResultModel friendList(HttpServletRequest request) {
        String userId=request.getHeader("userId");
        return iUserFriendService.friendList(userId);
    }
    /**
     * 我的消息列表
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/newsList")
    public ResultModel newsList(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String fromId=map.get("fromId").toString();
        String toId=map.get("toId").toString();
        return iUserFriendService.newsList(fromId,toId);
    }
    /**
     * 发送消息
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/sendMsg")
    public ResultModel sendMsg(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        String toUserId=map.get("toId").toString();
        String msg=map.get("msg").toString();
        return iUserFriendService.sendMsg(userId,toUserId,msg);
    }
}
